import 'package:flutter/cupertino.dart';

import '../model/page_status.dart';
import '../widget/indicator/loading.dart';

/// FileName page_notifier
///
/// @Author lax
/// @Date 2023/5/5
///
/// @Description

class PageNotifier extends ChangeNotifier {
  /// 页面状态
  PageStatus pageStatus = PageStatus.loading;

  bool get pageIsNormal => pageStatus == PageStatus.normal;

  bool get pageIsLoading => pageStatus == PageStatus.loading;

  bool get pageIsError => pageStatus == PageStatus.error;

  /// 修改页面状态
  void pageStatusChanged(bool success) {
    pageStatus = success ? PageStatus.normal : PageStatus.error;
    notifyListeners();
  }

  /// 网络请求
  Future<void> requestData() async {}

  /// 重新加载
  Future<void> reloadData({bool indicator = false}) async {
    pageStatus = PageStatus.loading;
    notifyListeners();
    if (indicator == true) {
      Loading.show();
    }
    await requestData();
    if (indicator == true) {
      Loading.dismiss();
    }
  }
}
